package com.abbas.smartCity.ui;

import android.widget.Button;
import android.widget.EditText;

import com.abbas.smartCity.R;
import com.abbas.smartCity.base.BaseActivity;
import com.abbas.smartCity.bean.ResponseBean;
import com.abbas.smartCity.retroft.ICallback;

import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.Call;

/**
 * 修改密码页面
 */
public class ChangePasswordActivity extends BaseActivity {

    private EditText oldPasswordEt;
    private EditText newPasswordEt;
    private Button okBt;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_password;
    }

    @Override
    protected String setCustomTitle() {
        return "修改密码";
    }

    @Override
    protected void initView() {
        oldPasswordEt = (EditText) findViewById(R.id.old_password_et);
        newPasswordEt = (EditText) findViewById(R.id.new_password_et);
        okBt = (Button) findViewById(R.id.ok_bt);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {
        okBt.setOnClickListener((v) -> {
            final Map<String, Object> params = getMap();
            params.put("oldPassword",oldPasswordEt.getText().toString());
            params.put("newPassword",newPasswordEt.getText().toString());
            final RequestBody requestBody = createRequestBody(params);
            api.changePassword(requestBody).enqueue(new ICallback<ResponseBean>() {
                @Override
                public void onSuccess(Call<ResponseBean> call, ResponseBean data) {
                    showToast(data.getMsg());
                }
            });
        });
    }
}